package com.mezz.bones.im.logic.config;

import com.mezz.bones.im.logic.interceptor.ImAuthInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author mezz
 * @date 2023-01-28 17:00
 * @description:
 */
@Slf4j
@Configuration
public class ImAuthConfig implements WebMvcConfigurer {

    @Resource
    private ImAuthInterceptor imAuthInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(imAuthInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/error")
                .excludePathPatterns(excludePath())
        ;
    }

    private List<String> excludePath() {
        //免登录的接口路径 适配通配符 可使用免登录注解    @SaIgnore
        List<String> result = new ArrayList<>();
        result.add("/error/**");
        result.add("/test/**");
        result.add("/**/*.html");
        result.add("/**/*.js");
        result.add("/**/*.css");
        return result;
    }
}
